<?php
/**
 * CreateTime: 2023/11/24 10:43
 * User:LinQ
 */

namespace App\Models\CompanyDepartment;

use App\Models\BasicModel;
use App\Models\Users\UsersModel;

class DepartmentModel extends BasicModel
{
    protected $table = 'department';

    protected $primaryKey = 'department_id';

    protected $fillable = [
        "department_id",
        "com_id",
        "department_name",
        "pid",
        "quick_sub_department",
        "responsible_user_id",
        "owner_id",
        "status",
        "created_at",
        "updated_at"
    ];

    protected $casts = [
        "department_id" => "integer",
        "com_id" => "integer",
        "department_name" => "string",
        "pid" => "integer",
        "quick_sub_department" => "string",
        "responsible_user_id" => "integer",
        "owner_id" => "integer",
        "status" => "integer",
        "created_at" => "string",
        "updated_at" => "string"
    ];

    protected $hidden = [
        "created_at",
        "updated_at",
        "status",
        "quick_sub_department"
    ];

    /**
     * 内置创建人枚举，若筛选查询 owner_str 则可以通过 owner_id as owner_str自动转换枚举
     * @param $value
     * @return string
     */
    public function getResponsibleUserStrAttribute($value): string
    {
        $value = (int)$value;
        return UsersModel::select(['user_id','name'])->find($value)->name ?? "-";
    }


}
